package com.cooqe;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.nio.charset.StandardCharsets;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2023/11/19-2023
 * @Description: 这里用一句话描述这个类的作用
 */
@Controller
@Slf4j
public class TestController {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public void testSendMq(){
        for (int i = 0; i < 100; i++) {
            String msg="";
            Message message = new Message("topic", "", msg.getBytes(StandardCharsets.UTF_8));
            rocketMQTemplate.asyncSend("topic", message,
              //回调
              new SendCallback() {
                @Override
                public void onSuccess(SendResult sendResult) {
                    log.info("消息发送成功!!!");
                }

                @Override
                public void onException(Throwable throwable) {
                    log.info("发送异常!!!", throwable.getMessage());
                }
            });
        }
    }
}